<?php
namespace My\Controller;

use Utuo\BackgroundController;

class DynaFormController extends BackgroundController {
	
	protected  $verify = array(
		'0' => "未审核",
		'1' => "审核通过",
		'3' => "审核未通过",
	);
	
	public function _initialize() {
		$this->setControllerTitle('表单管理');
		$this->setActionTitle(array(
				'index' => '表单列表',
				'subList' => '提交内容列表',
				'recycle' => '回收站',
		));
		$this->setActionNav(array(
				'index',
				'recycle' 
		));
	}
	
	public function indexAction() {
		$this->getLists( 0 );
	}
	
	public function recycleAction() {
		$this->getLists( 1 );
	}
	
	// 获取列表
	private function getLists($is_deleted) {
		$condition = array(
			'is_deleted' => $is_deleted,
			'cid' => $this->aid,
		);
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$dynaFormLists = M('DynaForm')->where($condition)->field('*')->limit($pagesize)->page($page)->order('id desc')->select();
		$count = M('DynaForm')->where($condition)->count();
		$this->assign('dynaFormLists', $dynaFormLists);
		$this->showPage($count, $pagesize);
		$this->display();
	}
	
	// 显示用户提交列表
	public function subListAction() {
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$formId = I('id', 0, "intval");
		$dynaForm = M('DynaForm')->find($formId);
		$dynaForm and $dynaForm['config'] = unserialize($dynaForm["config"]);
		$dynaFormDataLists = M("DynaFormData")->where("form_id=%d", $formId)->limit($pagesize)->page($page)->select();
		$dynaFormDataCount = M("DynaFormData")->where("form_id=%d", $formId)->count();
		foreach ($dynaFormDataLists as &$v) {
			$v['verifyOptions'] = $this->getOption($this->verify, $v['verify'], null);
			$v['data'] = unserialize($v['data']);
		}
		$this->showPage($dynaFormDataCount, $pagesize);
		$this->assign("dynaFormDataLists", $dynaFormDataLists);
		$this->assign("dynaForm", $dynaForm);
		$this->display();
	}
	
	// 设置状态
	public function setReadStatusAction() {
		$this->ajaxSetStatus("DynaFormData");
	}
	
	// 移除
	public function removeDynaFormDataAction() {
		$this->ajaxRemove("DynaFormData");
	}
	
	// 恢复
	public function restoreAction() {
		$this->ajaxRestore("DynaForm");
	}
	
	// 删除
	public function deleteAction() {
		$this->ajaxDelete("DynaForm");
	}
	
	// 移除
	public function removeAction() {
		$this->ajaxRemove();
	}
	
	// 设置状态 
	public function setStatusAction() {
		$this->ajaxSetStatus();
	}
	
	// 设置审核状态
	public function setVerifyStatusAction() {
		$id = I('id',0, 'intval');
		$verify = I('verify', 0, 'intval');
		false !== M("DynaFormData")->where(array('id'=>$id))->setField('verify', $verify) and $this->ajaxSuccess("设置成功 ");
		$this->ajaxSuccess("设置失败");
	}
	
}

?>